# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-uuidm
_pkgname=uuidm
pkgver=0.9.8
pkgrel=2
pkgdesc="Universally unique identifiers (UUIDs) for OCaml"
url="https://erratique.ch/software/uuidm"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
depends_dev="$pkgname=$pkgver-r$pkgrel ocaml-cmdliner-dev"
makedepends="
	$depends_dev
	ocaml
	ocamlbuild
	ocaml-compiler-libs
	ocaml-findlib
	ocaml-topkg
	cmd:opam-installer
	"
subpackages="$pkgname-dev $pkgname-tools"
source="$pkgname-$pkgver.tar.bz2::https://erratique.ch/software/uuidm/releases/uuidm-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml
options="!check" # FIXME: run tests if possible!

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	ocaml pkg/pkg.ml build \
		--with-cmdliner true
}

package() {
	opam-installer -i \
		--prefix="$pkgdir"/usr \
		--libdir="$pkgdir/$_ocamldir" \
		--docdir="$builddir"/.omit \
		$_pkgname.install
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

tools() {
	pkgdesc="$pkgdesc (command line utilities)"
	depends=""

	amove usr/bin
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
d5073ae49c402ab3ea6dc8f86bc5b8cc14129437e23e47da4d91431648fcb31c4dce6308f9c936c58df9a2c6afda61d77105a3022e369cca4e4c140320e803b5  ocaml-uuidm-0.9.8.tar.bz2
"
